<template>
  <div class="app-main-container">
    <!-- <div class="app-main-title">操作日志</div> -->
    <QueryForm
      v-model="filters"
      :query-form-config="queryFormConfig"
      @handleQuery="getList(1)"
      @clear="clearList"
    />
    <el-table
      ref="table"
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      border
      fit
      :header-row-class-name="'table-header'"
      class="doumee-element-table"
    >
      <el-table-column
        align="center"
        label="操作人手机号"
        min-width="140"
        show-overflow-tooltip
        prop="userPhone"
      />
      <el-table-column
        align="center"
        label="操作人账号"
        show-overflow-tooltip
        min-width="140"
        prop="userAdmin"
      />
      <el-table-column
        align="center"
        label="操作人姓名"
        show-overflow-tooltip
        prop="userName"
        min-width="140"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="操作时间"
        prop="makeTime"
        min-width="160"
      />
      <el-table-column
        align="center"
        label="操作说明"
        show-overflow-tooltip
        prop="makeType"
        min-width="200"
      />
      <el-table-column
        align="center"
        label="操作类型"
        prop="makeCode"
        show-overflow-tooltip
        min-width="200"
      />
      <el-table-column
        align="center"
        label="操作内容"
        prop="makeInfo"
        min-width="300"
        show-overflow-tooltip
        max-height="200"
      />
      <el-table-column align="center" label="操作状态" min-width="110" prop="type">
        <template slot-scope="scope">
          {{ scope.row.status == "1" ? "操作失败" : "操作成功" }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="响应信息"
        prop="masseger"
        min-width="300"
        show-overflow-tooltip
      />
    </el-table>
    <!-- <div class="flex-cc doumee-pagination">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :current-page.sync="pagination.page"
        hide-on-single-page
        @current-change="getList"
      />
    </div> -->
    <Pagination
      :total="total"
      :page="pagination.page"
      @current-change="getList"
      @SizeChange="handleSizeChange"
    />
  </div>
</template>

<script>
import { parseTime } from '@/utils/index'
import { operateLog } from '@/api'
import Pagination from '@/components/paginations'
import { queryFormConfig } from './config'
export default {
  name: 'Operatelog',
  components: {
    Pagination
  },
  data() {
    return {
      queryFormConfig,
      list: [],
      pagination: {
        page: 1,
        rows: 10
      },
      total: 0,
      statusList: [
        { value: '0', label: '企业单位' },
        { value: '1', label: '个人/非企业单位' }
      ],
      filters: {},
      listLoading: true
    }
  },
  created() {
    this.getList(1)
  },
  mounted() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  activated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  methods: {
    clearList() {
      this.filters = {}
      this.getList(1)
    },
    handleSizeChange(value) {
      this.pagination.rows = value
      this.getList(1)
    },
    showSource(value) {
      this.statusList.forEach(e => {
        if (e.value === value) {
          return e.label
        }
      })
    },
    getList(page) {
      this.listLoading = true
      const { filters, pagination } = this
      if (page) {
        pagination.page = page
        this.pagination.page = page
      }
      if (pagination.page === 1) {
        pagination.firstQueryTime = parseTime(new Date())
      }
      if (filters.time && filters.time.length > 0) {
        filters.makeStartTime = filters.time[0]
        filters.makeEndTime = filters.time[1]
      } else {
        filters.makeStartTime = ''
        filters.makeEndTime = ''
      }
      operateLog({ pagination, param: { ...filters }}).then(res => {
        this.listLoading = false
        if (res.errorCode === '000000') {
          this.list = res.recordList
          this.total = res.totalCount
        }
      }).catch(() => {
        this.listLoading = false
      })
    }
  }
}
</script>
